# Maintainer (MSYS2): Michael Hansen <zrax0111@gmail.com>

_variant=-${KF5_VARIANT:-shared}
source "$(dirname ${BASH_SOURCE[0]})"/../mingw-w64-PKGBUILD-common/kde-frameworks5
_kde_f5_init_package "${_variant}" "breeze-icons"
pkgver=5.109.0
pkgrel=1
arch=('any')
mingw_arch=('mingw32' 'mingw64' 'ucrt64' 'clang64' 'clang32' 'clangarm64')
pkgdesc="Breeze icon themes (mingw-w64)"
license=('LGPL')
makedepends=("${MINGW_PACKAGE_PREFIX}-extra-cmake-modules>=${pkgver}"
             "${MINGW_PACKAGE_PREFIX}-ninja"
             "${MINGW_PACKAGE_PREFIX}-cc"
             "${MINGW_PACKAGE_PREFIX}-python-lxml"
             "unzip")
depends=()
if [ "${_variant}" = "-static" ]; then
  _kde_f5_add_depends "${_variant}" "${MINGW_PACKAGE_PREFIX}-qt5${_namesuff}"
else
  depends+=("${MINGW_PACKAGE_PREFIX}-qt5-base")
fi
groups=("${MINGW_PACKAGE_PREFIX}-kf5")
# Use zip file because the tarball contains both file and directory symlinks.
# "https://download.kde.org/stable/frameworks/${pkgver%.*}/${_basename}-${pkgver}.tar.xz"{,.sig}
source=("https://download.kde.org/stable/frameworks/${pkgver%.*}/${_basename}-${pkgver}.zip"
        01-mingw-python-script.patch)
sha256sums=('0f281ab1be317aa69f2818652ed5b9dbdfc814ed62d655191adcfdf45e4f560b'
            '2589efa413e5540668eaa6156d415b9e423cba566643aaef449392992bcb46c2')
validpgpkeys=('53E6B47B45CEA3E0D5B7457758D0EE648A48B3BB') # David Faure <faure@kde.org>

prepare() {
  mkdir -p build-${MSYSTEM}${_variant}
  cd ${_basename}-${pkgver}
  patch -p1 -i ${srcdir}/01-mingw-python-script.patch
}

build() {
  local -a extra_config
  cd build-${MSYSTEM}${_variant}
  if [ "${_variant}" = "-static" ]; then
    extra_config+=( -DBUILD_SHARED_LIBS=NO )
  fi

  # See craft-blueprints-kde/kde/frameworks/tier1/breeze-icons/breeze-icons.py.
  # Install Qt resource files only. SVG files are not required by KDE apps in Windows.
  _kde_f5_build_env
  ${MINGW_PREFIX}/bin/cmake.exe \
    -G "Ninja" \
    -DCMAKE_BUILD_TYPE=$(_kde_f5_CMAKE_BUILD_TYPE) \
    "${_kde_f5_KDE_INSTALL_DIRS[@]}" \
    -DBUILD_TESTING=OFF \
    -DECM_DIR=${MINGW_PREFIX}/share/ECM \
    -DPython_EXECUTABLE=${MINGW_PREFIX}/bin/python.exe \
    -DPython_ROOT_DIR=${MINGW_PREFIX} \
    -DPython_FIND_REGISTRY=NEVER \
    -DBINARY_ICONS_RESOURCE=ON \
    -DSKIP_INSTALL_ICONS=ON \
    "${extra_config[@]}" \
    ../${_basename}-${pkgver}

  ${MINGW_PREFIX}/bin/cmake.exe --build ./
}

package() {
  cd build-${MSYSTEM}${_variant}
  DESTDIR="${pkgdir}" ${MINGW_PREFIX}/bin/cmake.exe --install ./

  # KDE apps won't get an icon theme by default on Windows unless it's
  # provided via <QStandardPaths::GenericDataLocation>/icontheme.rcc
  # TODO: Make this better...
  _kde_f5_build_env
  install -Dm644 icons/breeze-icons.rcc "${pkgdir}/${QT5_PREFIX}"/bin/data/icontheme.rcc
}
